using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using TONLI.TJOA.Domain;
using TONLI.TJOA.Common;
using ComponentArt.Web.UI;

namespace TONLI.TJOA.Anquan {
    public partial class AQK_XXFLBZ : System.Web.UI.Page {
        protected void Page_Load(object sender, EventArgs e) {
            if (!Page.IsPostBack && !FolderGrid.IsCallback) {
                StrWhere = null;
                BuildFolderGrid();
                FolderGrid.DataBind();
                buildTree();

            }
            AjaxPro.Utility.RegisterTypeForAjax(typeof(AQK_XXFLBZ));
        }

        #region webMethod
        [AjaxPro.AjaxMethod]
        public TJOA_AQK_XXFLBZ GetNewWF_HD() {
            return new TJOA_AQK_XXFLBZ();
        }
        [AjaxPro.AjaxMethod]
        public int AddWF_HD(TJOA_AQK_XXFLBZ obj) {
            DataService.BaseService().Create<TJOA_AQK_XXFLBZ>(obj);
            return 1;
        }
        [AjaxPro.AjaxMethod]
        public int DelWF_HD(string id) {
            TJOA_AQK_XXFLBZ obj = new TJOA_AQK_XXFLBZ();
            obj.SUID = id;
            DataService.BaseService().Delete<TJOA_AQK_XXFLBZ>(obj);
            return 1;
        }
        [AjaxPro.AjaxMethod]
        public TJOA_AQK_XXFLBZ GetWF_HD(object obj) {
            TJOA_AQK_XXFLBZ ret = DataService.BaseService().GetOneByKey<TJOA_AQK_XXFLBZ>(obj);
            return ret;
        }
        [AjaxPro.AjaxMethod]
        public int UpdateWF_HD(TJOA_AQK_XXFLBZ obj) {
            DataService.BaseService().Update<TJOA_AQK_XXFLBZ>(obj);
            return 1;
        }
        #endregion
        private void buildTree() {
            IList list = DataService.BaseService().GetList("SelectTJOA_AQK_XXFLBZListByParentid", "root");
            foreach (TJOA_AQK_XXFLBZ obj in list) {
                TreeViewNode node1 = new ComponentArt.Web.UI.TreeViewNode();
                node1.ID = obj.SUID;
                node1.Text = obj.WTD;
                node1.ImageUrl = "file.gif";
                treeview1.Nodes.Add(node1);
            }
        }
        private void BuildFolderGrid() {
            FolderGrid.DataSource = DataService.BaseService().GetList("SelectTJOA_AQK_XXFLBZListByParentid", StrWhere);
        }
        public string StrWhere {
            get { return Session["TJOA_AQK_XXFLBZ_Parentid"] == null ? "" : Session["TJOA_AQK_XXFLBZ_Parentid"].ToString(); }
            set { Session["TJOA_AQK_XXFLBZ_Parentid"] = value; }
        }
        protected void FolderGrid_NeedRebind(object sender, EventArgs e) {
            FolderGrid.DataBind();
        }

        protected void FolderGrid_NeedDataSource(object sender, EventArgs e) {
            BuildFolderGrid();
        }

        protected void FolderGrid_PageIndexChanged(object sender, ComponentArt.Web.UI.GridPageIndexChangedEventArgs e) {
            FolderGrid.CurrentPageIndex = e.NewIndex;
        }

        protected void FolderGrid_SortCommand(object sender, ComponentArt.Web.UI.GridSortCommandEventArgs e) {
            FolderGrid.Sort = e.SortExpression;
        }

        public void FolderCallBack_Callback(object sender, ComponentArt.Web.UI.CallBackEventArgs args) {
            if (!string.IsNullOrEmpty(args.Parameter)) {
                StrWhere = args.Parameter;
            }
            BuildFolderGrid();
            FolderGrid.DataBind();

            FolderGrid.RenderControl(args.Output);
        }
    }
}